#include <QApplication>
#include <QSettings>

#include "Configuration.h"

Configuration::Configuration(QObject *parent) :
    QObject(parent)
{}

Configuration::~Configuration()
{}

QString Configuration::alarmSoundPath() const
{
    return mAlarmSoundPath;
}

int Configuration::checkInterval() const
{
    return mCheckInterval;
}

void Configuration::load()
{
    QSettings settings(
        QSettings::IniFormat,
        QSettings::UserScope,
        qApp->organizationName(),
        qApp->applicationName()
    );

    mAlarmSoundPath = settings.value( "config/alarmSoundPath", "" ).toString();
    mCheckInterval = settings.value( "config/checkInterval", 5 ).toInt(); // 5 minutes.
    mPlaySound = settings.value( "config/playSound", false ).toBool();
    mShowPopup = settings.value( "config/showPopup", true ).toBool();
}

bool Configuration::playSound() const
{
    return mPlaySound;
}

void Configuration::save()
{
    QSettings settings(
        QSettings::IniFormat,
        QSettings::UserScope,
        qApp->organizationName(),
        qApp->applicationName()
    );

    settings.setValue( "config/alarmSoundPath", mAlarmSoundPath );
    settings.setValue( "config/checkInterval", mCheckInterval );
    settings.setValue( "config/playSound", mPlaySound );
    settings.setValue( "config/showPopup", mShowPopup );

    settings.sync();
}

void Configuration::setAlarmSoundPath( const QString &alarmSoundPath )
{
    mAlarmSoundPath = alarmSoundPath;
}

void Configuration::setCheckInterval( int checkInterval )
{
    mCheckInterval = checkInterval;
}

void Configuration::setPlaySound( bool playSound )
{
    mPlaySound = playSound;
}

void Configuration::setShowPopup( bool showPopup )
{
    mShowPopup = showPopup;
}

bool Configuration::showPopup() const
{
    return mShowPopup;
}
